﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using control.Biz;

namespace control.Dal
{
    class DalChiTietPhieuNhap
    {

        internal static List<BizChiTietPhieuNhap> GetListByIDPhieu(int p)
        {
            var cts = from ct in DalCommon.SachDB.ChiTietPhieuNhaps
                      where ct.IDPhieuNhap == p
                      select new BizChiTietPhieuNhap()
                      {
                          Sach = DalSach.GetSachByID(ct.IDSach),
                          SoLuong = (int)ct.SoLuong,
                          DonGia = (int)ct.DonGia,
                      };
            return cts.ToList<BizChiTietPhieuNhap>();
        }

        internal static void Insert(BizChiTietPhieuNhap bizChiTietPhieuNhap)
        {
            Sach_WebDataContext db = DalCommon.SachDB;
            ChiTietPhieuNhap ct = new ChiTietPhieuNhap()
            {
                IDSach = bizChiTietPhieuNhap.Sach.IdSach,
                IDPhieuNhap = bizChiTietPhieuNhap.PhieuNhap.ID,
                SoLuong = bizChiTietPhieuNhap.SoLuong,
                DonGia = bizChiTietPhieuNhap.DonGia,
            };
            db.ChiTietPhieuNhaps.InsertOnSubmit(ct);
            db.SubmitChanges();
        }



        internal static void DeleteCTofPhieu(BizPhieuNhap bizPhieuNhap)
        {
            Sach_WebDataContext db = DalCommon.SachDB;
            var cts = from ct in db.ChiTietPhieuNhaps
                      where ct.IDPhieuNhap == bizPhieuNhap.ID
                      select ct;
            IEnumerable<ChiTietPhieuNhap> lct = cts;
             db.ChiTietPhieuNhaps.DeleteAllOnSubmit(lct);
             db.SubmitChanges();
        }
    }
}
